<template class="search-box">
	<view>
		<gy-search @Toclick="toHeadle()"></gy-search>
	</view>

	<view>

		<view class="scroll-view-container">
			<!-- 左侧滑动 -->
			<scroll-view class="left-scroll" scroll-y="true" :style="{height:wh + 'px'}">
				<view @click="changeActiveAndChangeCat(index)"
					:class="{'left-scroll-item':true,active:index === Isactive}" v-for="(item,index) in cateLevel"
					:key="index">
					{{item.cat_name}}
				</view>
			</scroll-view>
			<!-- 右侧滑动 -->
			<scroll-view class="right-scroll" scroll-y="true" :style="{height:wh + 'px'}" :scroll-top="srollTop">
				<view v-for="(item,index) in cateLevel2" class="level2" :key="index">
					<view class="level2-title">
						/{{item.cat_name}}/
					</view>
					<view class="level3-list">
						<view @click="gotoGoodsList(item.cat_id)" class="level3-list-item"
							v-for="(item,index3) in item.children" :key="index3">
							<image :src="item.cat_icon"></image>
							<text>{{item.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>

		</view>
	</view>
</template>

<script>
	import mixin from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[mixin],
		data() {
			return {
				wh: 0,
				Isactive: 0,
				cateLevel: [],
				cateLevel2: [],
				srollTop: 0
			};
		},
		methods: {
			toHeadle() {
				console.log('headle ok')
				uni.navigateTo({
					url:'/subpackage/search/search'
				})
			},
			gotoGoodsList(id) {
				console.log(id)
				uni.navigateTo({
					url: '/subpackage/goods/goods?cid=' + id
				})
			},
			changeActiveAndChangeCat(index) {
				this.Isactive = index
				this.cateLevel2 = this.cateLevel[index].children
				console.log(this.cateLevel2)
				this.srollTop = this.srollTop ? 0 : 1
			},
			async getCateList() {
				const {
					data
				} = await uni.$http.get('http://192.168.1.11:8080/get/cat')
				this.cateLevel = data.result
				this.cateLevel2 = data.result[0].children
			}
		},
		onLoad() {
			const sy = uni.getSystemInfoAsync()
			this.wh = sy.windowHeight
			this.getCateList()
		}
	}
</script>

<style lang="scss">
	.search-box {
		position: sticky;
		top: 0px;
		z-index: 999;
	}

	.scroll-view-container {
		display: flex;
		height: 100vh;

		/* 确保容器占满视口高度 */
		.left-scroll-item {

			line-height: 60px;
			text-align: center;
			font-size: 12px;
			background-color: #f6f6f6;

			&.active {
				background-color: #d6d6d6;
				position: relative;

				&::before {
					content: ' ';
					display: block;
					height: 60px;
					width: 2px;
					background-color: #da0000;
					position: absolute;
					left: 0;
				}
			}
		}

		.left-scroll {
			width: 30%;
		}

		.right-scroll {
			width: 70%;

			.level2-title {
				font-size: 12px;
				font-weight: bold;
				text-align: center;
				padding: 15px 0px;
			}

			.level3-list {
				display: flex;
				flex-wrap: wrap;

				.level3-list-item {
					width: 33.33%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					image {
						height: 60px;
						width: 60px;
					}
				}
			}

		}
	}
</style>